from tools.base_page import BasePage


class PerSon(BasePage):
    def touxiang(self):
        grzl = ("id", "com.znb.zxx:id/user_icon_view")  # 个人资料
        tx = ("id", "com.znb.zxx:id/icon_part_view")
        xc = ("id", "com.znb.zxx:id/dialog_system_edia_album")  # 从相册选择
        photo = ("id", "com.android.gallery3d:id/album_name")  # 图片文件夹
        jpg = ("id", "com.android.gallery3d:id/iv_thumbnail")  # 图片
        gouxuan = ("id", "com.android.gallery3d:id/head_select_right")  # 勾选照片按键
        self.find_element(self.driver, grzl).click()
        self.find_element(self.driver, tx).click()
        self.find_element(self.driver, xc).click()
        self.find_element(self.driver, photo).click()
        self.find_element(self.driver, jpg).click()
        self.find_element(self.driver, gouxuan).click()
        return self.get_toast_text(self.driver)

    def nicheng(self, data):
        nc = ("xpath",
              "//*[@resource-id='com.znb.zxx:id/page_success_view']//*[@resource-id='com.znb.zxx:id/nickname_part_view']/android.widget.ImageView")
        nc_input = ("id", "com.znb.zxx:id/info_edit_view")
        wancheng = ("xpath", "//*[@text='完成']")
        self.find(nc).click()
        self.find(nc_input).send_keys(data)
        self.find(wancheng).click()
        return self.get_toast_text(self.driver)

    def sex(self):
        sex = ("id", "com.znb.zxx:id/gender_view")  # 性别
        sex_accom = ("id", "btnSubmit")  # 性别完成
        self.find(sex).click()
        self.go_swipe(0.5, 0.9, 0.5, 0.8)
        self.find(sex_accom).click()
        return self.get_toast_text(self.driver)

    def birthday(self):
        birthday = ("id", "com.znb.zxx:id/birthday_view")
        bir_accom = ("id", "com.znb.zxx:id/btnSubmit")  # 生日设置完成
        self.click_element(self.driver, birthday)
        self.go_swipe(0.9, 0.9, 0.9, 0.8)
        self.click_element(self.driver, bir_accom)
        return self.get_toast_text(self.driver)

    def region(self):
        diqu_locator = ("id", "location_view")
        wc_locator = ("xpath", "//*[@text='完成']")
        self.click_element(self.driver, diqu_locator)
        self.go_swipe(0.2, 0.9, 0.2, 0.7)
        self.go_swipe(0.5, 0.9, 0.5, 0.7)
        self.go_swipe(0.8, 0.9, 0.8, 0.7)
        # self.click_element(self.driver, wc_locator)

        # return self.get_toast_text(self.driver)

    def mail(self, data):
        mail = ("id", "com.znb.zxx:id/mail_view")  # 邮箱
        send_mail = ("id", "com.znb.zxx:id/info_edit_view")  # 输入邮箱
        wc_locator = ("xpath", "//*[@text='完成']")
        self.click_element(self.driver, mail)
        self.find_element(self.driver, send_mail).send_keys(data)
        self.click_element(self.driver, wc_locator)
        try:
            return self.get_toast_text(self.driver)
        finally:
            self.back_activity(1)
